--- 模块功能：利用http上传日志到指定服务器.
-- @author zhangFenghe
-- @module http.logUpload
-- @license MIT
-- @copyright zhangFenghe
-- @release 2022.04.29
module(..., package.seeall)

require "httpTask"
require "nvm"
require "io"
require "logGenerator"
nvm.init("config.lua", true)

local date, uploadVideoUrl, clientNo
local function logsUpdateTask(logsName, logsPath)
    httpTask.postMultipartFormData(uploadVideoUrl, nil,
                                   {files = {[logsName] = logsPath}},
                                   {txt = "multipart/form-data"}, 60000)
end
function uploadLogTask(tjsondata)
    date, uploadVideoUrl, clientNo = tjsondata["date"],
                                     nvm.get("uploadVideoUrl"),
                                     nvm.get("info")[1]
    local fileName = clientNo .. "-" .. date
    local logName, errorName, eqlogName, selfCheckName = fileName .. "-log.txt",
                                                         fileName ..
                                                             "-error.txt",
                                                         fileName ..
                                                             "-eqlog.txt",
                                                         fileName ..
                                                             "-selfCheck.txt"
    local logPath, errorPath, eqlogPath, selfCheckLogPath =
        logGenerator.LOG_DIR_PATH .. "/" .. logName,
        logGenerator.LOG_DIR_PATH .. "/" .. errorName,
        logGenerator.LOG_DIR_PATH .. "/" .. eqlogName,
        logGenerator.LOG_DIR_PATH .. "/" .. selfCheckName
    log.info("日志名称", logName, "日志路径", logPath)
    if io.exists(logPath) then sys.taskInit(logsUpdateTask, logName, logPath) end
    if io.exists(errorPath) then
        sys.taskInit(logsUpdateTask, errorName, errorPath)
    end
    if io.exists(eqlogPath) then
        sys.taskInit(logsUpdateTask, eqlogName, eqlogPath)
    end
    if io.exists(selfCheckLogPath) then
        sys.taskInit(logsUpdateTask, selfCheckName, selfCheckLogPath)
    end
end
